package chj;

import chj.Bookmanage.Badd;
import chj.Bookmanage.Bdelete;
import chj.Bookmanage.Bfind;
import chj.Bookmanage.Bupdate;
import chj.bookface.BKJPanel;
import ldz.Show.LoginWindow;
import ldz.Show.UserManagementGUI;
import nz.LibraryStatsApp;
import xxh.BorrowRecordUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LogOn {
    public  void Chjmain() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        // TODO Auto-generated method stub

        JFrame frame = new JFrame("图书管理系统-管理员");//主菜单窗口
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());
       //开设面板，方便设置位置
        JPanel pan1 = new JPanel();
        JPanel pan2 = new JPanel();
        JPanel pan3 = new JPanel();
        JPanel pan4 = new JPanel();
        BKJPanel pan6 = new BKJPanel("src/chj/image/bg.jpg");//放置图片

        //提示框
        JLabel label1 = new JLabel("管理操作");

        //按钮
        JButton button1 = new JButton("书籍添加");
        JButton button2 = new JButton("书籍删除");
        JButton button3 = new JButton("书籍修改");
        JButton button4 = new JButton("书籍查询");
        JButton button5 = new JButton("用户管理");
        JButton button6 = new JButton("书籍统计");
        JButton button7 = new JButton("查询借阅记录");
        JButton button8 = new JButton("退出登录");
        button1.setOpaque(false);
        button2.setOpaque(false);
        button3.setOpaque(false);
        button4.setOpaque(false);
        button5.setOpaque(false);
        button6.setOpaque(false);
        button7.setOpaque(false);
        button8.setOpaque(false);
        //设置颜色格式
        pan6.setBounds(0, 0, 1300, 800);

        //设置字体大小对象
        Font font = new Font("宋体", Font.BOLD, 80);//标题字体大小
        Font f = new Font("宋体", Font.BOLD, 30);//提示框字体大小
        Font f1 = new Font("宋体", Font.BOLD, 20);//text
        //设置按钮的大小
        button1.setPreferredSize(new Dimension(250, 75));
        button2.setPreferredSize(new Dimension(250, 75));
        button3.setPreferredSize(new Dimension(250, 75));
        button4.setPreferredSize(new Dimension(250, 75));
        button5.setPreferredSize(new Dimension(250, 75));
        button6.setPreferredSize(new Dimension(250, 75));
        button7.setPreferredSize(new Dimension(250, 75));
        button8.setPreferredSize(new Dimension(250, 75));

        button1.setFont(f);
        button2.setFont(f);
        button3.setFont(f);
        button4.setFont(f);
        button5.setFont(f);
        button6.setFont(f);
        button7.setFont(f);
        button8.setFont(f);
        label1.setFont(font);//设置标题字体

        //向面板中添加组件
        pan1.add(label1);
        pan1.setBounds(50, 30, 1100, 120);//大标题
        pan1.setOpaque(false);
        pan2.add(button1);
        pan2.add(button2);
        pan2.add(button3);
        pan2.add(button4);
        pan2.add(button5);
        pan2.add(button6);
        pan2.add(button7);
        pan2.add(button8);
        pan2.setBounds(450, 150, 300, 800);



        //各项操作监听,button1--button4
        button4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Bfind.BookLookFram();//图书查询
            }
        });

        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Badd.bookAddFram();//图书添加
            }
        });
        button3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Bupdate.bookUpDataFram();//修改图书
            }
        });
        button2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Bdelete.BookDeleteFram();//删除图书
            }
        });
        button5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UserManagementGUI().setLocationRelativeTo(null);//用户管理
            }
        });
        button6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LibraryStatsApp app = new LibraryStatsApp();
                app.setLocationRelativeTo(null);
                app.setVisible(true);  //书籍统计
            }
        });
        button7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                BorrowRecordUI borrowRecordUI = new BorrowRecordUI(null);
                borrowRecordUI.setLocationRelativeTo(null);
                borrowRecordUI.setVisible(true);
            }
        });
        button8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                new LoginWindow().setLocationRelativeTo(null);
            }
        });
       //向容器中添加JPanel面板
        pan1.setOpaque(false);
        pan2.setOpaque(false);
        frame.add(pan1);
        frame.add(pan2);
        frame.add(pan3);
        frame.add(pan4);
        frame.add(pan6);
        //窗口设置
        frame.setBounds(310, 100, 1300, 900);
        frame.setResizable(false);//设置窗口不能扩大
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
}
